package com.workpaper.app.workpaper.daily.view;

import java.util.Calendar;
import java.util.Date;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.workpaper.app.cache.resource.ViewInfoCache;
import com.workpaper.app.consts.common.CommonViewConsts;
import com.workpaper.app.consts.workpaper.DailyWorkpaperViewConsts;
import com.workpaper.app.workpaper.daily.entity.DailyWorkpaper;
/**
 * 工作日报信息展示对话框
 * @author zhouyujun
 *
 */
public class DailyWorkpaperInfoDialog extends Dialog {
	/**
	 * 日期选择器
	 */
	private DateTime dateSelector;
	/**
	 * 内容文本
	 */
	private StyledText contentText;
	/**
	 * 所有人
	 */
	private Text masterText; 
	/**
	 * 备注
	 */
	private StyledText remarkText;
	
	private DailyWorkpaper dailyWorkpaper;
	
	public DailyWorkpaperInfoDialog(Shell parentShell, DailyWorkpaper dailyWorkpaper) {
		super(parentShell);
		this.dailyWorkpaper = dailyWorkpaper;
	}

	
	/**
	 * 配置窗口标题、图标等信息
	 * @param newShell
	 */
	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText(ViewInfoCache.get(DailyWorkpaperViewConsts.WPD_Add_Title));	//标题
//		newShell.setImage(null);	//图标
	}


	
	@Override
	protected Point getInitialSize() {
		return new Point(400, 400);
	}

	/**
	 * 内容设置
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite container = (Composite) super.createDialogArea(parent);
		GridLayout layout = new GridLayout(2, false);
		layout.marginRight = 6;
		container.setLayout(layout);

		//创建用日期：标签、日期控件 输入框
		Label dsNameLabel = new Label(container, SWT.NONE);
		dsNameLabel.setText(ViewInfoCache.get(DailyWorkpaperViewConsts.WPD_EditText_Date));
		//水平右对齐，垂直居中，水平方向不填充空白，垂直方向不填充空白， 跨1行，跨1列
		dsNameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
//		dsNameLabel.setImage(CacheImage.getAppImage(ImagePath.LOGIN_USERNAME_ICO));
		dateSelector = new DateTime(container, SWT.DATE);
		dateSelector.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
		dateSelector.setEnabled(false);
		Date worDate = dailyWorkpaper.getWorkDate();
		Calendar wdCalendar = Calendar.getInstance();
		wdCalendar.setTime(worDate);
		dateSelector.setYear(wdCalendar.get(Calendar.YEAR));
		dateSelector.setMonth(wdCalendar.get(Calendar.MONTH));
		dateSelector.setDay(wdCalendar.get(Calendar.DAY_OF_MONTH));
		
		//创建内容：
		Label contentLabel = new Label(container, SWT.NONE);
		contentLabel.setText(ViewInfoCache.get(DailyWorkpaperViewConsts.WPD_EditText_Content));
		//水平右对齐，垂直居中，水平方向不填充空白，垂直方向不填充空白， 跨1行，跨1列
		contentLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		contentText = new StyledText(container, SWT.BORDER);
		contentText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
		contentText.setEnabled(false);
		contentText.setText(dailyWorkpaper.getContent());
		//创建所有人：
		Label executorLabel = new Label(container, SWT.NONE);
		executorLabel.setText(ViewInfoCache.get(DailyWorkpaperViewConsts.WPD_EditText_Master));
		//水平右对齐，垂直居中，水平方向不填充空白，垂直方向不填充空白， 跨1行，跨1列
		executorLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		masterText = new Text(container, SWT.BORDER);
		masterText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
		masterText.setEnabled(false);
		masterText.setText(dailyWorkpaper.getMaster());
		//创建备注：
		Label remarkLabel = new Label(container, SWT.NONE);
		remarkLabel.setText(ViewInfoCache.get(DailyWorkpaperViewConsts.WPD_EditText_Remark));
		//水平右对齐，垂直居中，水平方向不填充空白，垂直方向不填充空白， 跨1行，跨1列
		remarkLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		remarkText = new StyledText(container, SWT.BORDER);
		remarkText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
		remarkText.setEnabled(false);
		remarkText.setText(dailyWorkpaper.getRemark());
		return container;
	}

	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		//创建返回按钮
		createButton(parent, IDialogConstants.CANCEL_ID, ViewInfoCache.get(CommonViewConsts.ButtonText_Return), true);
	}

	@Override
	protected void cancelPressed() {
		super.cancelPressed();
	}
}
